package logic

import (
	"context"
	"zg_four_week3/esserver/esserverclient"

	"zg_four_week3/esclient/internal/svc"
	"zg_four_week3/esclient/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EsIndexLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEsIndexLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsIndexLogic {
	return &EsIndexLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EsIndexLogic) EsIndex(req *types.EsIndexRequest) (resp *types.EsIndexResponse, err error) {
	// todo: add your logic here and delete this line
	index := req.Index
	_, err = l.svcCtx.EsServer.EsIndex(l.ctx, &esserverclient.EsIndexRequest{
		Index: index,
	})
	var r types.EsIndexResponse
	r.Code = -1
	if err != nil {
		r.Msg = err.Error()
		return &r, nil
	}
	r.Code = 200
	r.Msg = "success"
	return &r, nil
}
